<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Other extends MY_Admin {
    function __construct()
    {
        parent :: __construct();
        $this->lang->load('other', 'chinese');
    }

    public function index()
    {
        $config['base_url']         = site_url('admins/other');
        $config['total_rows']       = 200;
        $config['per_page']         = $this->pageLimit;
        $config['uri_segment']      = 3;
        //$config['use_page_numbers'] = TRUE;
        //echo $this->uri->segment(3);
        $this->pagination->initialize($config);

        $parm['where'] = array(
            'types'=>'page',
            'm.type'=>'category'
        );

        $datas['others'] = $this->Entries->getTopic($parm, $this->uri->segment(3), $this->pageLimit);

        $this->load->view('admins/other/base', $datas);
    }

    public function delete()
    {
        if($this->Entries->getOne($this->uri->segment(4)))
            if($this->Entries->deleteTopic($this->uri->segment(4)))
                $this->goback(1);
            else
                $this->goback(0);
        else
            $this->goback(0);
    }
    
    public function edit()
    {
        $this->load->view('admins/other/edit');
    }

    public function doEdit()
    {
       // Validation rules
        $validation = array(
            array(
                'field' => 'description',
                'label' => lang('description'),
                'rules' => 'required|trim'
            ),
            array(
                'field' => 'titles',
                'label' => lang('titles'),
                'rules' => 'required|trim'
            ),
            array(
                'field' => 'texts',
                'label' => lang('texts'),
                'rules' => 'required|trim'
            )
        );

        // Set the validation rules
        $this->form_validation->set_rules($validation);
        $user_data = array();
        // Convert the array to an object
        $user_data['titles']			= $this->security->xss_clean($this->input->post('titles'));
        $user_data['description'] 		= $this->security->xss_clean($this->input->post('description'));
        $user_data['texts']             = $this->security->xss_clean($this->input->post('texts'));
        $user_data['tag']   	        = $this->security->xss_clean($this->input->post('tag'));
        $user_data['slug']   	        = $this->security->xss_clean($this->input->post('slug'));
        $user_data['page']   	        = $this->security->xss_clean($this->input->post('category'));
        $user_data['parent']   	        = $this->input->post('parent');
        $user_data['eid']   	        = $this->input->post('eid');
        $user_data['types']   	        = $this->input->post('types');
        if ($this->form_validation->run())
        {
            //$this->Entries->add($this->input->post());
            if($this->Entries->add($user_data))
                $this->goback(1);
            else
                $this->goback(0);
        }
        else
        {
            echo validation_errors(); 
        }
    }
}